/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.view.customer;

import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import src.domain.customer.Customer;
import src.services.customer.CustomerConverter;

/**
 *
 * @author jasuke
 */
@ManagedBean
@SessionScoped
public class AutoCustomerBean {

    /**
     * Creates a new instance of AutoCustomerBean
     */
    private Customer selectedCustomer;  
    private List<Customer> customers;  
    
    public AutoCustomerBean() {
        customers = CustomerConverter.customerDB;
    }
    
    public List<Customer> getCustomers() {
        return customers;
    }

    public Customer getSelectedCustomer() {
        return selectedCustomer;
    }

    public void setSelectedCustomer(Customer selectedCustomer) {
        this.selectedCustomer = selectedCustomer;
    }
    
    public List<Customer> completeCustomer(String query) {
        List<Customer> suggestions = new ArrayList<>();
		
            for(Customer p : customers) {
                if(p.getCustomerName().startsWith(query))
                    suggestions.add(p);
            }
		
	return suggestions;
    }
}
